package com.study.test.demo.observer;

import java.util.Observable;

/**
 * jdk里的观察者模式：被观察者 继承Observable
 * @Author hupengming
 * @ClassName GPer
 * @Date 2023-03-14  11:25
 * @Version 1.0
 */
public class GPer extends Observable {

    private String name = "GPer生态圈";

    private static final GPer gper = new GPer();

    private GPer(){}

    public static GPer getInstance(){
        return gper;
    }

    public String getName() {
        return name;
    }

    public void publishQuestion(Question question){
        System.out.println(question.getUser() + "在" + this.name + "上提交了一个问题。");
        setChanged();
        notifyObservers(question); //通知所有的观察者
    }
}
